@using DNA.Mvc.Text;
@model Article
@{
    var comments = Model.Comments.OrderBy(c => c.Posted);
    var website = WebSiteContext.Current.Web.Name;
}
@UIHelper.SectionHeader(Html.Global("publishing", "Comments") + " (" + Model.Comments.Count.ToString() + ")")
<ul class="d-horizontal-list">
    @if (Request.IsAuthenticated)
    {
        <li>
        @UIHelper.SubscriptionLink(Ajax, Model.PermaLink.ToLower())
        </li>
    }
    <li>
        @Ajax.Dna().Link(Url.Action("rss", "Article", new { Area = "Publishing", website = website, id = Model.ID })).Text("rss").ImageIcons(@Url.Content("~/Content/Images/rss.png")).GetHtml()
    </li>
    <li>
        @Ajax.Dna().Link(Url.Action("atom", "Article", new { Area = "Publishing", website = website, id = Model.ID })).Text("atom").ImageIcons(@Url.Content("~/Content/Images/rss.png")).GetHtml()
    </li>
</ul>
<br />
@if (comments.Count() > 0)
{
    var i = 0;
    <ul class="d-comment-list">
        @foreach (var comment in comments)
        {
            var cmm = new CommentWrapper(comment);
            <li  id="@("comment_"+cmm.ID)" class="@((i % 2 == 0) ? "d-comment-post" : "d-comment-odd-post")">
                <table style="width: 100%; margin-bottom: 10px; clear: left;">
                    <tr>
                        <td colspan="2" class="d-post-title">
                            <a rel="nofollow" href="@cmm.PermaLink" title="@Html.Global("publishing", "Permalink")">
                                #</a>&nbsp;@cmm.Title
                            <div style="float: right">
                                <ul class="d-horizontal-list">
                                    @*<li>@Ajax.Dna().Button("btnAlert" + cmm.ID.ToString()).ChangeType(ButtonTypes.LinkButton).Text("Alert").ImageIcons(Url.Content("~/content/images/icon_alert_16.gif")).GetHtml()</li>*@
                                    @if (Request.IsAuthenticated && (User.IsWebOwner() || Model.IsOwner(User.Identity.Name)))
                                    {
                                        if (WebSiteContext.Current.IsAuthorized<Article>("Spam"))
                                        {
                                            <li>
                                            @using (Html.BeginForm("Spam", "Article", new { Area = "Publishing", id = cmm.ID }, FormMethod.Post))
                                            {
                                                @Ajax.Dna().Button("btnSpam" + cmm.ID.ToString()).ChangeType(ButtonTypes.LinkButton).Submit().Text("Spam").ImageIcons(Url.Content("~/content/images/icon_spam_16.gif")).GetHtml()
                                            }
                                        </li>
                                        }
                                        <li>
                                        @Ajax.Dna().Button("btnDeleteComment"+cmm.ID.ToString()).ChangeType(ButtonTypes.LinkButton).LocText("RES_DELETE").Click("_deleteComment("+cmm.ID+");").ImageIcons(Url.Content("~/content/images/icon_delete_16.png")).GetHtml()</li>
                                    }
                                </ul>
                            </div>
                        </td>
                    </tr>
                    <tr>
                        <td style="width: 150px; vertical-align: top;">
                            <div class="d-avatar" style="width: 60px;">
                                <img src="@cmm.GetAvatar(Context, 60)" alt="" width="60" height="60" /></div>
                            <div>
                                @if (!cmm.IsAnonymousComment)
                                { 
                                    @Html.UserLink(cmm.UserName)
                                }
                                else
                                { 
                                    @cmm.UserName
                                }
                            </div>
                            <div>@Html.Global(comment.Posted)</div>
                        </td>
                        <td style="vertical-align: top;">
                            <div style="min-height: 80px;">
                                @TextEngine.SafeHtml(comment.Body)</div>
                            <div style="padding: 5px;">
                                @if (comment.IsTrackback)
                                { 
                                    <a style="color: #cccccc; font-style: italic;" href="@comment.WebSite" target="_blank"  rel="nofollow">
                                        <span>- @Html.Global("publishing", "TrackbackFrom"):</span>@comment.WebSite</a>
                                }
                                @if (comment.IsPingback)
                                {
                                    <a  style="color: #cccccc; font-style: italic;" href="@comment.WebSite" target="_blank" rel="nofollow">
                                        <span>- @Html.Global("publishing", "PingbackFrom"):</span>@comment.WebSite</a>
                                }
                            </div>
                        </td>
                    </tr>
                </table>
            </li>
                                i++;
        }
    </ul>
}
else
{ 
    <div class="ui-state-highlight ui-corner-all" style="padding: 20px; margin: 5px;
        display: block;">
        <span style="float: left; margin-right: 0.3em;" class="ui-icon ui-icon-info"></span>
        @Html.Global("Publishing", "NoComments")
    </div>
}
@if ((Request.IsAuthenticated) || (Model.Category.AllowAnonymousPostComment))
{
    if (Model.AllowComments)
    {
    <div id="dna_ui_article_comments">
        @UIHelper.SectionHeader(Html.Global("Publishing", "WriteComment"))
        <div id="CommentFields">
            @using (Ajax.BeginAjaxForm("AddComment", "Article", new jQueryAjaxOptions()
            {
                HttpMethod = "POST",
                AutoBlocking = true,
                OnComplete = " if ($('#isCommentAdded').val()=='True') $('#commentlist').load('" + Url.Action("Comments", "Article", new { Area = "Publishing", id = Model.ID }) + "');"
            },
    new RouteValueDictionary(new { Area = "Publishing", id = Model.ID }), null))
            {
                Html.RenderAction("AddComment", "Article", new { Area = "Publishing", id = Model.ID });
            }
        </div>
    </div>
    }
    if ((Model.TotalComments > 0) && (!Model.AllowComments))
    { 
    <div class="ui-highlight" style="padding: 20px; margin: 5px; display: block;">
       @Html.Global("publishing", "CommentIsClosed")</div>
    }
}
<script type="text/javascript">
    function _deleteComment(id) {
        $dna.confirm("@Html.Global("RES_QUESTION")","@Html.Global("publishing","DeleteCommentQuestion")", function () {
            $.ajax({
                type: "POST",
                url: "@Url.Action("DeleteComment","Article",new {Area="Publishing"})",
                data: {id:id},
                success: function () {
                    $("#comment_" + id).remove();
                }
            });
        });
    }
</script>
@Html.StartupScripts()
